<div id="content">

	<h1>Gradebook</h1>
	
	<div style="margin:0 0px 0 0px;">
	
		<div>
			<% form_remote_tag :url => {:controller=>"dashboard", :action => "save_grades"} do -%>

				<%= 
					assignmentsPerRow = @assignments.length
					cnt = 0
					result = "<table style=\'border:dashed 1px #CCC;\'>\n<tr>\n<td>"
					result += hidden_field_tag(:assignmentsPerRow, assignmentsPerRow)
					(0...@assignments.length).each do |assignment|
						result += "<td>"
						result += "  #{h(@assignments[assignment].title[0..13])}
									<br /> <span class='flash'>(#{h(@assignments[assignment].points_possible)})</span>"
						result += "</td>\n"
						if assignment.modulo(assignmentsPerRow) == assignmentsPerRow-1 or assignment == @assignments.length-1
							result += "\n</tr>\n"
							
							@students.each{ |student|
								result += "\n<tr class=\'" + cycle('list-line-odd', 'list-line-even') + '\'><td> <a onclick=\'javascript:alert("' + h(@stuInfo[student.user]) + '");\'> ' + h(student.surname) + ", " + h(student.firstname) + '</a></td>'
								(0...assignmentsPerRow).each{ |i|
									if @grades[student.id][i] != nil
										result += "<td>" + text_field_tag( "#{cnt}", "#{h(@grades[student.id][i].grade.to_s)}", 'size' => 5) + "</td>\n"
									else
										result += "<td>" + text_field_tag( "#{cnt}", "0", 'size' => 5) + "</td>\n"
									end
									cnt = cnt + 1
								}
								result += "</tr>\n"
							}
							
							result += "<tr>\n<td>"
						end
					end
					result += "\n</tr>\n</table><div style='text-align:center;'>" + submit_tag("Save") + "</div>"
					result
					
				%>
	
			<% end %>
				
		</div>
		<br />
		<br />
		
		
	
		

		<div style="border: dashed 1px #CCC; padding:3px 15px;">
			<h3 style="text-align:center;">Add an Assignment</h3>
			<div style="text-align:center;">
				<p>
					<% form_remote_tag :url => {:controller=>"dashboard", :action => "addAssignment"} do -%>
					    <%= text_field_tag :newAssignment, "<assignment name>"%>
					    <%= text_field_tag :newPoints, "<points possible>"%>
					    <%= submit_tag "Add" %><br />
					    <%= text_area_tag :newAssignmentDesc , "<assignment description>", :cols=>45 %>	
					<% end %>
			    </p>
		    </div>
		</div>

		<br />
		
		<div style="border: dashed 1px #CCC; padding:3px 15px;">
			<div style="float:left;">
				<h3>Remove an Assignment</h3>
				<table border="0">
					<tr>
						<% form_remote_tag :url => {:controller=>"dashboard", :action => "removeAssignment"} do -%>
							<div style="border: dashed 1px #CCC; padding:3px 15px;">
								    <td><%= select_tag :oldAssignment, @assignmentss %></td>
								    <td><%= submit_tag "Remove" %></td>
							</div>
						<% end %>
					</tr>
				</table>
			</div>
			<div style="float:right;">
				<h3>Remove All Assignments</h3>
				<% form_remote_tag :url => {:controller=>"dashboard", :action => "removeAllAssignments"} do -%>
					<p style="margin:3px; text-align:right;"><%= submit_tag "Remove All" %></p>
				<% end %>
			</div>
			<div style="clear:both;"></div>	
		</div>
		
		<br />

		<div style="border: dashed 1px #CCC; padding:3px 15px;">
			<div style="float:left;">
				<h3>Remove a Student Account</h3>
				<table border="0">
					<tr>
						<% form_remote_tag :url => {:controller=>"dashboard", :action => "removeStudent"} do -%>
							<div style="border: dashed 1px #CCC; padding:3px 15px;">
								    <td><%= select_tag :username, @studentss %></td>
								    <td><%= submit_tag "Remove" %></td>
							</div>
						<% end %>
					</tr>
				</table>
			</div>
			<div style="float:right;">
				<h3>Remove All Student accounts</h3>
				<% form_remote_tag :url => {:controller=>"dashboard", :action => "removeAllStudents"} do -%>
					<p style="margin:3px; text-align:right;"><%= submit_tag "Remove All" %></p>
				<% end %>
			</div>
			<div style="clear:both;"></div>
		</div>
	
		<p style="text-align:center; margin:15px 0px; font-style:italic;">
			By removing a student you remove them from the system.
			They will not be able to login in the future without making a new account.
			All grades you have entered for that student will be lost.
		</p>

		
	</div>

</div>

